package cn.iocoder.yudao.module.vos.controller.admin.activityfailednumbers;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.vos.controller.admin.activityfailednumbers.vo.*;
import cn.iocoder.yudao.module.vos.dal.dataobject.activityfailednumbers.ActivityFailedNumbersDO;
import cn.iocoder.yudao.module.vos.service.activityfailednumbers.ActivityFailedNumbersService;

@Tag(name = "管理后台 - 活动任务失败的具体名单号码信息")
@RestController
@RequestMapping("/vos/activity-failed-numbers")
@Validated
public class ActivityFailedNumbersController {

    @Resource
    private ActivityFailedNumbersService activityFailedNumbersService;

    @PostMapping("/create")
    @Operation(summary = "创建活动任务失败的具体名单号码信息")
    @PreAuthorize("@ss.hasPermission('vos:activity-failed-numbers:create')")
    public CommonResult<Long> createActivityFailedNumbers(@Valid @RequestBody ActivityFailedNumbersSaveReqVO createReqVO) {
        return success(activityFailedNumbersService.createActivityFailedNumbers(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新活动任务失败的具体名单号码信息")
    @PreAuthorize("@ss.hasPermission('vos:activity-failed-numbers:update')")
    public CommonResult<Boolean> updateActivityFailedNumbers(@Valid @RequestBody ActivityFailedNumbersSaveReqVO updateReqVO) {
        activityFailedNumbersService.updateActivityFailedNumbers(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除活动任务失败的具体名单号码信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('vos:activity-failed-numbers:delete')")
    public CommonResult<Boolean> deleteActivityFailedNumbers(@RequestParam("id") Long id) {
        activityFailedNumbersService.deleteActivityFailedNumbers(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除活动任务失败的具体名单号码信息")
                @PreAuthorize("@ss.hasPermission('vos:activity-failed-numbers:delete')")
    public CommonResult<Boolean> deleteActivityFailedNumbersList(@RequestParam("ids") List<Long> ids) {
        activityFailedNumbersService.deleteActivityFailedNumbersListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得活动任务失败的具体名单号码信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('vos:activity-failed-numbers:query')")
    public CommonResult<ActivityFailedNumbersRespVO> getActivityFailedNumbers(@RequestParam("id") Long id) {
        ActivityFailedNumbersDO activityFailedNumbers = activityFailedNumbersService.getActivityFailedNumbers(id);
        return success(BeanUtils.toBean(activityFailedNumbers, ActivityFailedNumbersRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得活动任务失败的具体名单号码信息分页")
    @PreAuthorize("@ss.hasPermission('vos:activity-failed-numbers:query')")
    public CommonResult<PageResult<ActivityFailedNumbersRespVO>> getActivityFailedNumbersPage(@Valid ActivityFailedNumbersPageReqVO pageReqVO) {
        PageResult<ActivityFailedNumbersDO> pageResult = activityFailedNumbersService.getActivityFailedNumbersPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ActivityFailedNumbersRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出活动任务失败的具体名单号码信息 Excel")
    @PreAuthorize("@ss.hasPermission('vos:activity-failed-numbers:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportActivityFailedNumbersExcel(@Valid ActivityFailedNumbersPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ActivityFailedNumbersDO> list = activityFailedNumbersService.getActivityFailedNumbersPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "活动任务失败的具体名单号码信息.xls", "数据", ActivityFailedNumbersRespVO.class,
                        BeanUtils.toBean(list, ActivityFailedNumbersRespVO.class));
    }

}